#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

int x = 0, y = 1;

pthread_t p1, p2;

void *p1_fun(void *arg);
void *p2_fun(void *arg);

int main(int argc, char const *argv[])
{
    if (pthread_create(&p1, NULL, p1_fun, (void *)0) != 0)
    {
        printf("create p1 failed!\n");
        return -1;
    }

    if (pthread_create(&p2, NULL, p2_fun, (void *)0) != 0)
    {
        printf("create p2 failed!\n");
        return -1;
    }

    pthread_join(p1, NULL);
    pthread_join(p2, NULL);
    
    return 0;
}

void *p1_fun(void *arg)
{
    for (x = 0; x < 100; x++)
    {
        printf("x = %d\n", x);
        sleep(1);
    }

    pthread_exit(NULL);
}

void *p2_fun(void *arg)
{
    for (y = 0; y < 100; y++)
    {
        printf("y = %d\n", y);
        sleep(1);
    }

    pthread_exit(NULL);
}
